
//
//  PromptView.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/2/6.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "PromptView.h"

@implementation PromptView

-(void)creatView{
    self.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
   
    UIView *view=[UIView new];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.width.mas_equalTo(_mainW*0.7);
        make.height.mas_equalTo(200);
    }];
    view.backgroundColor=[UIColor whiteColor];
    view.layer.cornerRadius=4;
    
    
    UIView *topView=[UIView new];
    [view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(55);
    }];
    topView.backgroundColor=_backgroundColor;
    
    UILabel *titleLabel=[UILabel new];
    [topView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    titleLabel.text=@"提示";
    titleLabel.font=[UIFont systemFontOfSize:18];
    titleLabel.textColor=[UIColor whiteColor];
    
    UILabel *neiLabel=[UILabel new];
    [view addSubview: neiLabel];
    [neiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topView.mas_bottom).mas_equalTo(20);
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(_mainW/2);
    }];
    neiLabel.textAlignment=NSTextAlignmentLeft;
    neiLabel.font=[UIFont systemFontOfSize:17];
    neiLabel.numberOfLines=0;
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"温馨提示：试听结束，需支付继续收听!"];
    [attrStr addAttribute:NSForegroundColorAttributeName value:ColorWithRGB(99, 99, 99) range:NSMakeRange(0, 5)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:ColorWithRGB(0, 156, 216) range:NSMakeRange(5, 4)];
     [attrStr addAttribute:NSForegroundColorAttributeName value:ColorWithRGB(99, 99, 99) range:NSMakeRange(9, 1)];
     [attrStr addAttribute:NSForegroundColorAttributeName value:ColorWithRGB(0, 156, 216) range:NSMakeRange(10, 3)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:ColorWithRGB(99, 99, 99) range:NSMakeRange(13, 5)];
    neiLabel.attributedText=attrStr;
    
    
    _btn=[UIButton new];
    [view addSubview:_btn];
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(_mainW*0.45);
        make.bottom.mas_equalTo(-15);
    }];
    [_btn setTitle:@"立即支付" forState:0];
    [_btn setTitleColor:[UIColor whiteColor] forState:0];
    _btn.layer.cornerRadius=4;
    _btn.backgroundColor=_backgroundColor;
}
#pragma mark————————————————————点击屏幕关闭键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self ];
    
    if (!(touchPoint.y>_mainH/2-100&&touchPoint.y<_mainH/2+100&&touchPoint.x>_mainW*0.15&&touchPoint.x<_mainW*0.85)) {
        [self removeFromSuperview];
    }
}

@end
